Date: 2019-10-15
R version: 3.5.0
*Corresponding author: matthew.malishev@gmail.com
This document can be found at https://github.com/darwinanddavis/githubpres

 

R session info

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.5.0  tools_3.5.0     htmltools_0.3.6 yaml_2.2.0      Rcpp_1.0.2      rmarkdown_1.14 
 [7] knitr_1.23      xfun_0.8        digest_0.6.20   evaluate_0.14  

Overview

This document showcases why R is dope.

You can write in-line code if you want to differentiate between when you are typing normally or highlighting model parameters, for example.

Equations like this \(t' = \gamma(t - vx/c^{2})\), to appear within text lines.

Create links to your website.

Make footnotes1.

Use different headings

Like this subheading

Create quoted text

Pump the bass in the trunk //
It rattled like a baby hand //
Except this toy cost 80 grand //
And I’m crazy tan, from all the places that I’ve been //
Just from writing words with a pen //

Just like , but more versatile.

Define equations

Accordingly, we write the eigenfunction of a spinless particle as the superposition of plane wave states of momentum (\(\pi\)) and energy (\(Ej\)) having amplitudes \(a(\pi,Ej)\)

\[ \phi n(r,t) = \sum_{i, j} a(p_{i},E_{j}) e^{ \frac{i} {h} (p_{i} \cdot r - E_{j}t) } \]

where, for convenience, we have suppressed the eigenfunction indices in \(\phi n(r,t)\) and \(an(\pi,Ej)\). Using periodic boundary conditions, the normalization of \(\phi n(r,t)\) in (1) yields

\[ \frac {1} {V_{o}T_{o}h^{4}} \int \phi \cdot (r,t) \phi (r,t)d^{3}rdt = \sum a \cdot (p_{i},E_{j})a(p_{i},E_{j}) = 1 \]          

Embed images/gifs:

Science.

Create, alter, and embed plots

Figure 1. Example of a stock plot embedded into a PDF from RMarkdown.

Show plots with associated code

require(viridis)
bm <- 0
par(las = 1, bty = "n")
xlim <- c(-5, 5)
ylim <- c(0, 0.5)
set.seed(12)
N <- 2000
rr <- rnorm(N)
rr2 <- rnorm(N^2)
rr3 <- rnorm(N + 0.3)
rrd <- density(rr)
rrd2 <- density(rr2)
rrd3 <- density(rr3)
main <- paste0(N, " points but plot better")
xlab <- "Points in space"
if (bm == 1) {
    layout(matrix(c(rep(1, 3), 2:4), 2, 3, byrow = TRUE))
    sc <- 1
    plot(rr, las = 1, bty = "n", col = adjustcolor(viridis(N), 0.5), pch = 20, cex = runif(10, 1, 5), 
        main = main, xlab = xlab)
    for (r in list(rrd, rrd2, rrd3)) {
        plot(r, xlim = xlim, ylim = ylim, main = "")
        polygon(r, col = adjustcolor(viridis(250)[sc], 0.5), border = viridis(250)[sc])
        sc <- sc + 100
    }
} else {
    par(mfrow = c(1, 1))
    plot(rr, las = 1, bty = "n", col = adjustcolor(viridis(N), 0.5), pch = 20, cex = runif(10, 1, 5), 
        main = main, xlab = xlab)
}

Figure 2. Example of a plot with improved graphics and its associated code embedded into a PDF from RMarkdown.

And tables

Table 1. Definitions of model parameters for individual hosts and parasites. Dimensions and units: -, dimensionless; cm, centimetres; J, Joules; L, length.

Parameter Definition Dimension
(unit)
L structural length cm
ee scaled reserve density J (cm3)
D host development
RH energy in reproduction buffer J

Embed code from different languages

This is R code

if (pck == 1) {
    p <- c("rJava", "RNetLogo")
    remove.packages(p)
    # then install rJava and RNetLogo from source
    install.packages("rJava", repos = "https://cran.r-project.org/")
    install.packages("RNetLogo", repos = "https://cran.r-project.org/")
}

shell/bash

echo "Hello Bash!"  
pwd # check working dir
git init # initialise git

Octave (and MATLAB from the RMatlab package).

RMatlab documentation.

b = [4; 9; 2] # Column vector
A = [ 3 4 5;
      1 3 1;
      3 5 9 ]
x = A \ b     # Solve the system Ax = b

HTML

<!-- links-->
        <div class="footer">
            <a href="dd_feed.html" 
            class="transition fade_in">
                Latest post
            </a>
            &nbsp; &nbsp; &nbsp;
            <a href="dd_contact.html" 
            class="transition fade_in">
                Contact
            </a>
            &nbsp; &nbsp; &nbsp;
            <a href="dd_subscribe.html"
            class="transition fade_in">
                Subscribe
            </a>
        </div>

CSS

body {
  color: red;
}

Javascript to access html and css

$('.title').css('color', 'red')

Python

x = 'hello, python world!'
print(x.split(' '))

Here’s a complete list of available languages

names(knitr::knit_engines$get())
 [1] "awk"       "bash"      "coffee"    "gawk"      "groovy"    "haskell"   "lein"      "mysql"    
 [9] "node"      "octave"    "perl"      "psql"      "Rscript"   "ruby"      "sas"       "scala"    
[17] "sed"       "sh"        "stata"     "zsh"       "highlight" "Rcpp"      "tikz"      "dot"      
[25] "c"         "fortran"   "fortran95" "asy"       "cat"       "asis"      "stan"      "block"    
[33] "block2"    "js"        "css"       "sql"       "go"        "python"    "julia"     "sass"     
[41] "scss"     

All from R!

References

Efthimiades, S., Physical meaning and derivation of Schrodinger and Dirac equations, Department of Natural Sciences, Fordham University. doi: d34464566.

Malishev, M., Bull, C. M., & Kearney, M. R. (2018). An individual‐based model of ectotherm movement integrating metabolic and microclimatic constraints. Methods in Ecology and Evolution, 9(3), 472-489.


  1. Where the footnote goes here and it is automatically formatted